package com.xxx.file;

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/22 14:06
 * @Copyright 博为峰
 */
public class FileReaderDemo {
    public static void main(String[] args) {
//        m1();
        try (FileReader fileReader = new FileReader("a.txt");) {
            int i1 = 0;//读到的字符数
            char[] chars = new char[1024];
            while ((i1 = fileReader.read(chars)) != -1) {
//                System.out.println(chars);
                String string = new String(chars, 0, i1);
                System.out.println(string);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void m1() {
        try (FileReader fileReader = new FileReader("a.txt");) {
            int i1 = 0;//读到的字符
            while ((i1 = fileReader.read()) != -1) {
                System.out.println((char) i1);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
